﻿namespace Sidvall.AuthorizationManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AuthorizationScopeUser : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser
    {
        #region Public Members

        #region AccessTime

        private System.Nullable<System.DateTime> _AccessTime;
        partial void OnBeforeAccessTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterAccessTimePropertyChanged();
        public System.Nullable<System.DateTime> AccessTime
        { 
            get
            {
                return _AccessTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AccessTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _AccessTime);
                    OnBeforeAccessTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AccessTime", eventData.Value, true, true);
                        OnAfterAccessTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region AuthorizationScopeId

        private long _AuthorizationScopeId;
        partial void OnBeforeAuthorizationScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterAuthorizationScopeIdPropertyChanged();
        public long AuthorizationScopeId
        { 
            get
            {
                return _AuthorizationScopeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AuthorizationScopeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _AuthorizationScopeId);
                    OnBeforeAuthorizationScopeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AuthorizationScopeId", eventData.Value, true, true);
                        OnAfterAuthorizationScopeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region CreatedTime

        private System.DateTime _CreatedTime;
        partial void OnBeforeCreatedTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterCreatedTimePropertyChanged();
        public System.DateTime CreatedTime
        { 
            get
            {
                return _CreatedTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _CreatedTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _CreatedTime);
                    OnBeforeCreatedTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("CreatedTime", eventData.Value, true, true);
                        OnAfterCreatedTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region IsActive

        private bool _IsActive;
        partial void OnBeforeIsActivePropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsActivePropertyChanged();
        public bool IsActive
        { 
            get
            {
                return _IsActive;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _IsActive = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsActive);
                    OnBeforeIsActivePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("IsActive", eventData.Value, true, true);
                        OnAfterIsActivePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UpdatedTime

        private System.DateTime _UpdatedTime;
        partial void OnBeforeUpdatedTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterUpdatedTimePropertyChanged();
        public System.DateTime UpdatedTime
        { 
            get
            {
                return _UpdatedTime;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UpdatedTime = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _UpdatedTime);
                    OnBeforeUpdatedTimePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UpdatedTime", eventData.Value, true, true);
                        OnAfterUpdatedTimePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserClaims

        private string _UserClaims;
        partial void OnBeforeUserClaimsPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserClaimsPropertyChanged();
        public string UserClaims
        { 
            get
            {
                return _UserClaims;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserClaims = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserClaims);
                    OnBeforeUserClaimsPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserClaims", eventData.Value, true, true);
                        OnAfterUserClaimsPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserContext

        private string _UserContext;
        partial void OnBeforeUserContextPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserContextPropertyChanged();
        public string UserContext
        { 
            get
            {
                return _UserContext;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserContext = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserContext);
                    OnBeforeUserContextPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserContext", eventData.Value, true, true);
                        OnAfterUserContextPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserId

        private string _UserId;
        partial void OnBeforeUserIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserIdPropertyChanged();
        public string UserId
        { 
            get
            {
                return _UserId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserId);
                    OnBeforeUserIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserId", eventData.Value, true, true);
                        OnAfterUserIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public AuthorizationScope AuthorizationScope { get; set; }
        #region LoadAuthorizationScopeAsync

        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync()
        {
            return await LoadAuthorizationScopeAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScope> LoadAuthorizationScopeAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.LoadAuthorizationScopeAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.AuthorizationScope;
        }
        public AuthorizationScope LoadAuthorizationScope(AuthorizationScope item)
        {
            LoadInstanceField("AuthorizationScope", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public AuthorizationScopeUser Copy()
        {
            return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Copy(this);
        }
        public AuthorizationScopeUser Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser item)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Import(this, item);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AuthorizationScopeUser> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortal.AuthorizationScopeUserManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Initialize(this, settings);
        }

        #endregion

        #region IAuthorizationScopeUser Members

        System.Nullable<System.DateTime> global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.AccessTime
        {
            get
            {
                return this._AccessTime;
            }
            set
            {
                this._AccessTime = value;
            }
        }
        long global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.AuthorizationScopeId
        {
            get
            {
                return this._AuthorizationScopeId;
            }
            set
            {
                this._AuthorizationScopeId = value;
            }
        }
        System.DateTime global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.CreatedTime
        {
            get
            {
                return this._CreatedTime;
            }
            set
            {
                this._CreatedTime = value;
            }
        }
        bool global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.IsActive
        {
            get
            {
                return this._IsActive;
            }
            set
            {
                this._IsActive = value;
            }
        }
        System.DateTime global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UpdatedTime
        {
            get
            {
                return this._UpdatedTime;
            }
            set
            {
                this._UpdatedTime = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UserClaims
        {
            get
            {
                return this._UserClaims;
            }
            set
            {
                this._UserClaims = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UserContext
        {
            get
            {
                return this._UserContext;
            }
            set
            {
                this._UserContext = value;
            }
        }
        string global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                this._UserId = value;
            }
        }
        global::Sidvall.AuthorizationManager.Data.IAuthorizationScope global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeUser.AuthorizationScope
        {
            get
            {
                return this.AuthorizationScope;
            }
            set
            {
                this.AuthorizationScope = (AuthorizationScope)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationScopeUser()
        {
        }
        public AuthorizationScopeUser(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public AuthorizationScopeUser(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeUserManager.Initialize(this);
        }

        #endregion
    }
}